Skip to contentMethod: CreateOperationsWithInheritanceRunner(Logger, PersistenceFactory, DataAccessor)
1: /**
2: * Copyright (C) 2019 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.jopa.test.runner;
14:
15: import cz.cvut.kbss.jopa.test.OWLClassQ;
16: import cz.cvut.kbss.jopa.test.OWLClassS;
17: import cz.cvut.kbss.jopa.test.OWLClassT;
18: import cz.cvut.kbss.jopa.test.environment.DataAccessor;
19: import cz.cvut.kbss.jopa.test.environment.PersistenceFactory;
20: import org.junit.jupiter.api.Test;
21: import org.slf4j.Logger;
22:
23: import static org.junit.jupiter.api.Assertions.*;
24:
25: public abstract class CreateOperationsWithInheritanceRunner extends BaseInheritanceRunner {
26:
27: protected CreateOperationsWithInheritanceRunner(Logger logger, PersistenceFactory persistenceFactory,
28: DataAccessor dataAccessor) {
29: super(logger, persistenceFactory, dataAccessor);
30: }
31:
32: @Test
33: void testPersistEntityWithMappedSuperclass() {
34: this.em = getEntityManager("PersistEntityWithMappedSuperclass", false);
35: em.getTransaction().begin();
36: em.persist(entityA);
37: em.persist(entityQ);
38: em.getTransaction().commit();
39: em.clear();
40:
41: assertNotNull(entityQ.getUri());
42: final OWLClassQ result = em.find(OWLClassQ.class, entityQ.getUri());
43: assertNotNull(result);
44: assertEquals(entityQ.getStringAttribute(), result.getStringAttribute());
45: assertEquals(entityQ.getParentString(), result.getParentString());
46: assertEquals(entityQ.getLabel(), result.getLabel());
47: assertNotNull(result.getOwlClassA());
48: assertEquals(entityQ.getOwlClassA().getUri(), result.getOwlClassA().getUri());
49: assertEquals(entityA.getStringAttribute(), result.getOwlClassA().getStringAttribute());
50: assertEquals(entityA.getTypes(), result.getOwlClassA().getTypes());
51: }
52:
53: @Test
54: void testPersistEntityWithEntitySuperclass() {
55: this.em = getEntityManager("PersistEntityWithEntitySuperclass", false);
56: em.getTransaction().begin();
57: em.persist(entityA);
58: em.persist(entityT);
59: em.getTransaction().commit();
60: em.clear();
61:
62: assertNotNull(entityT.getUri());
63: final OWLClassT result = em.find(OWLClassT.class, entityT.getUri());
64: assertNotNull(result);
65: assertEquals(entityT.getName(), result.getName());
66: assertEquals(entityT.getDescription(), result.getDescription());
67: assertEquals(entityT.getIntAttribute(), result.getIntAttribute());
68: assertNotNull(result.getOwlClassA());
69: assertEquals(entityA.getUri(), result.getOwlClassA().getUri());
70: assertEquals(entityA.getStringAttribute(), result.getOwlClassA().getStringAttribute());
71: assertEquals(entityA.getTypes(), result.getOwlClassA().getTypes());
72: }
73:
74: @Test
75: void testPersistEntityExtendedBySubEntity() {
76: this.em = getEntityManager("PersistEntityExtendedBySubEntity", false);
77: final OWLClassS entityS = new OWLClassS();
78: entityS.setName("Supertype");
79: entityS.setDescription("Supertype is a type with a subclass.");
80: em.getTransaction().begin();
81: em.persist(entityS);
82: em.getTransaction().commit();
83: em.clear();
84:
85: assertNotNull(entityS.getUri());
86: final OWLClassS resultS = em.find(OWLClassS.class, entityS.getUri());
87: assertNotNull(resultS);
88: assertEquals(entityS.getName(), resultS.getName());
89: assertEquals(entityS.getDescription(), resultS.getDescription());
90: em.clear();
91: assertNull(em.find(OWLClassT.class, entityS.getUri()));
92: }
93: }